package com.bwie.task;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bwie.mapper.TbProjectMapper;
import com.bwie.pojo.TbProject;
import com.bwie.pojo.TbUser;
import com.bwie.service.TbUserService;
import com.bwie.utils.MobileMessageUtil;
import com.bwie.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

@Configuration
public class Init {

    @Autowired
    TbProjectMapper tbProjectMapper;
    @Autowired
    TbUserService tbUserService;
    @Scheduled(cron = "0 0/1 * * * ?")
    public void init() {
        //查询未审核的
        List<TbProject> tbProjects = tbProjectMapper.selectList(new QueryWrapper<TbProject>().lambda().eq(TbProject::getProjectStatus, 2));
        //查询用户中的审核员,然后发送短信
        R user = tbUserService.TbUserList("user");
        String string = JSON.toJSONString(user.getData());
        List<TbUser> tbUsers = JSON.parseArray(string, TbUser.class);
        for (TbProject tbProject : tbProjects) {
            for (TbUser tbUser : tbUsers) {
                tbUserService.sendCode(tbUser.getUserMobile());
            }
        }
    }
}
